#include <iostream>
#include <thread>
#include <chrono>
#include <csignal>

#include "shm_utils.h"
#include "lighter.h"

int main() {
    try {
        auto* shm_ptr = link_shm_rw<MARKETStruct>("_v1");
        if (!shm_ptr) {
            std::cerr << "❌ 无法连接共享内存 _v1" << std::endl;
            return 1;
        }
        std::cout << "🚀 启动下单共享内存写入测试程序" << std::endl;

        uint64_t order_id = 1;
        OrderStruct order{};
        order.exchange = static_cast<uint8_t>(ExchangeEnum::LIGHTER);
        order.market_id = 0;
        order.order_id = order_id++;
        order.order_side = OrderSideEnum::ASK;   // 交替买卖
        order.size = 0.005;
        order.order_type = OrderActionEnum::CANCEL;
        order.price = 420000; // 模拟价格变化

        bool ok = shm_ptr->orderShm.push(order);
        if (ok) {
            std::cout << "✅ 写入订单: id=" << order.order_id
                      << " market=" << order.market_id
                      << " side=" << (order.order_side == OrderSideEnum::BID ? "BID" : "ASK")
                      << " price=" << order.price
                      << " size=" << order.size
                      << std::endl;
        } else {
            std::cerr << "❌ 写入失败" << std::endl;
        }
    } catch (const std::exception& e) {
        std::cerr << "❌ 异常: " << e.what() << std::endl;
        return 1;
    }
}
